package com.mdjukebox.http.controller.actions;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.util.struts.actions.DefaultAction;
import com.util.exceptions.InternalErrorException;
import com.util.sql.PlainActionProcessor;

import com.mdjukebox.model.adminfacade.actions.TodasCancionesAction;

/**
 * 
 * Listado de peticiones agrupadas por cancion
 * ordenadas por antiguedad
 *
 */
public class TodasCanciones extends DefaultAction{
	
	public ActionForward doExecute(ActionMapping mapping,
	        ActionForm form, HttpServletRequest request,
	        HttpServletResponse response)
	        throws IOException, ServletException, InternalErrorException {
	        
        /* Do . */
		ActionMessages errors = new ActionMessages(); 
		try {
			TodasCancionesAction action = new TodasCancionesAction();
            
            ArrayList canciones = (ArrayList) PlainActionProcessor.process(action);
            request.setAttribute("allcanciones", canciones);
            
        } catch (Exception e) {
        	if (log.isErrorEnabled()) log.error("Todas Canciones: ",e);
            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
                "Listado.Error", e.getMessage()));
        } 
        
        /* Return ActionForward. */
        if (errors.isEmpty()) {
            return mapping.findForward("ok");
        } else {
            saveErrors(request, errors);            
            return mapping.findForward("fallo");
        }
        
    }

}
